﻿#ifndef FSCONFIG_H
#define FSCONFIG_H

#include <QString>
#include <QStringList>
#include <QSettings>
#include <QDir>
#include <string.h>

#define CONF_PATH "conf"

///
/// 2024.5.22 配置文件分离：
/// ui.ini-界面(窗口，功能，加密狗)，
/// fs.ini-配置(镜头，电机控制);

typedef struct _UI_WINDOW_VAR{
    char    Title[64];              //标题
    char    ConfName[16];           //配置文件
    int     WindowMax;
    char    SoftKey[64];            //软件锁ID
}UI_WINDOW_VAR;

typedef struct _UI_FUNC_VAR{
    int     SysDog;
    int     AddSetup;
    int     AddSound;
    int     Debug;
    int     Log;
    int     Style;
}UI_FUNC_VAR;

typedef struct _UI_SOUND_VAR{
    char    ScanBeginName[64];
    char    ScanPhotoName[64];
}UI_SOUND_VAR;

typedef struct _UI_LIST_VAR{
    char    ListFilter[256];
    char    SaveResultPath[256];
    char    SaveImagePath[256];
    char    SaveDirFormat[64];
    int     SaveFileLen;
    char    ListCurDir[64];
    char    ListCurName[64];
}UI_LIST_VAR;

typedef struct _CONF_DESIGN_VAR{
    float   UIWindow4KWidth;
    float   UIWindow4KHeight;
    int     MouseWheelStep;
    int     MouseMoveStep;
    // int     LogoTitleWidth;
    // int     LogoTitleWidth4K;
    // int     LogoTitleHeight;
    // int     LogoTitleHeight4K;
    // int     LogoPhotoNums;
    int     LogoPhotoWidth;
    int     LogoPhotoWidth4K;
    int     LogoPhotoHeight;
    int     LogoPhotoHeight4K;
    char    LogoPhotoSheet1[256];
    char    LogoPhotoSheet2[256];
    // int     FocusAssistWidth;
    // int     FocusAssistWidth4K;
    // int     FocusAssistHeight;
    // int     FocusAssistHeight4K;
    // char    FocusAssistSheet[256];
    // int     FocusAssistNums;
    // int     FocusAssistBufLen;
    // int     FocusAssistBufLen4K;
    char    SplitterPhotoSizes[32];
    char    SplitterMainSizes[32];
    char    SplitterWindowSizes[32];
    // int     ImageFormat;
    // int     NegativeImage;
    int     SaveFormat;
    char    SaveFileExt[64];
    int     Para;
    int     SaveHeight;
    char    SaveDPIList[256];
    int     SaveDPI;
    // int     SaveNegative;
    // int     Negative;
    // int     Vertical;
    // int     Horizontal;
    // int     FilmPhoto;
    // int     RotatePhoto;
    // int     RotatePreview;
    // int     PreviewMode;
    int     Resolution;
    int     SaveImageWidth;
    int     SaveImageHeight;
    int     FrameEnable;
    // int     ImageCorrent;
    // int     PhotoImageEdit;
    // int     ImageEditWidth;
    // int     ImageEditHeight;
    // int     ListIconWidth;
    // int     ListIconWidth4K;
    // int     ListIconHeight;
    // int     ListIconHeight4K;
    // int     ListLeftWidth;
    // int     ListLeftWidth4K;
    // int     ListTextHeight;
    // int     ListTextHeight4K;
    // int     ListSpaceHeight;
    // int     ListSpaceHeight4K;
    // int     TooltipWindowWidth;
    // int     TooltipWindowWidth4K;
    // int     TooltipWindowHeight;
    // int     TooltipWindowHeight4K;
    // int     ImageZoomMax;
    int     ComboBoxItemHeight;
    int     ComboBoxItemHeight4K;
    int     UiSetupWindowWidth;
    int     UiSetupWindowHeight;
    int     UiSetupWindowWidth4K;
    int     UiSetupWindowHeight4K;
    int     FrameImageZoomMax;
    int     ResultImageZoomMax;
} CONF_DESIGN_VAR;

typedef struct _CONF_MVS_VAR{
    int     Debug;
    int     Log;
    bool    AutoFind;
    char    MvsStartTitle[32];
    char    MvsCloseTitle[32];
    char    MvsStartAcquisition[32];
    char    MvsCloseAcquisition[32];
    int     MvsSaveFrameNums;
    int     MvsPreviewBorder;
    int     MvsResultBorder;
} CONF_MVS_VAR;

typedef struct _CONF_PROC_VAR{
    int     ContourGaussian;
    int     ContourTwoBorder;
    int     ContourThresh;
    int     ContourMinWidth;
    int     ContourMinHeight;
    int     ContourMaxWidth;
    int     ContourUpDownBorder;
    int     ContourLeftRightBorder;
    int     ProcImageWidth;
    int     ProcTime;
} CONF_PROC_VAR;

typedef struct _CONF_UIM_VAR{
    char    Title[16];
    int     Debug;
    int     Log;
    char    UIMStartTitle[32];
    char    UIMCloseTitle[32];
    int     UIMUsbPort;
    int     UIMComPort;
    int     UIMCanTimer;
    int     UIMCanLimitTimer;
    int     UIMCanSelectTimer;
    int     EncodeTimer;
    int     EncodeNums;
    //上下
    char    FocusTitle[16];
    char    UIMFocusLabel[16];
    char    UIMFocusMoveTitle[2][16];
    int     UIMNodeIdFocus;
    int     UIMCanRateFocus;
    int     UIMCanRateFocusLocate;
    int     UIMCanStepFocus;
    int     UIMCanStepFocusLocate;
    int     UIMCanFocusOrg;
    int     UIMCanFocusFar;
    int     UIMCanFocusLimit1;
    int     UIMCanFocusLimit2;
    int     UIMCanFocusMode;
    //卷片扫描
    int     UIMCanRatePhoto;
    //右收片
    char    RightTitle[16];
    char    UIMRightMoveTitle[2][16];
    int     UIMNodeIdRight;
    int     UIMCanRateRight;
    int     UIMCanStepRight;
    int     UIMCanRateTakeupRight;
    int     UIMCanEncodeStop;
    int     UIMCanEncodeOver;
} CONF_UIM_VAR;

class fsConfig
{
public:
    fsConfig();
    ~fsConfig();

    void setUiName(const QString name){ uiName = name; };
    void setConfName(const QString path,const QString name);
    void setImagePath(const QString path){ ocrImagePath = path; };

    void readUi(void);
    void readConf(void);

    QVariant getConfig(const char *set, const char *key, const char *defaultValue);
    QVariant getUiWindow(const char *key, const char *defaultValue = "0");
    QVariant getUiFunc(const char *key, const char *defaultValue = "0");
    QVariant getUiList(const char *key, const char *defaultValue = "0");
    QVariant getConfigDesign(const char *key, const char *defaultValue = "0");
    QVariant getConfigMvs(const char *key, const char *defaultValue = "0");
    QVariant getConfigProc(const char *key, const char *defaultValue = "0");
    QVariant getConfigUim(const char *key, const char *defaultValue = "0");

    void saveConfigFuncSave(void);

    void saveConfigDesignWindow(void);
    void saveConfigDesignPara(void);
    void saveConfigDesignSaveImage(void);
    void saveConfigProc(void);
	void saveConfigListSave(void);

    void saveConfigUimConf(void);
    void saveConfigUimReset(void);
    void saveConfigUimPhoto(void);

public:
    UI_WINDOW_VAR winVar;
    UI_FUNC_VAR funcVar;
    UI_LIST_VAR listVar;

    CONF_DESIGN_VAR designVar;
    CONF_MVS_VAR mvsVar;
    CONF_PROC_VAR procVar;
    CONF_UIM_VAR uimVar;

private:
    QSettings *configIni;
    QString uiName;
    QString confName;
    QString ocrImagePath;
};

#endif // FSCONFIG_H
